package api_.collectionTest;

import java.util.Iterator;
import java.util.LinkedList;

public class LinkedListQueue
{
    private LinkedList queue;
    private int size;
    LinkedListQueue()
    {
        size = 0;
        queue = new LinkedList();
    }
    public void push(Object o)
    {
        queue.addLast(o);
        size++;
    }
    public Object pop()
    {
        if (queue.isEmpty())
        {
            return null;
        }
        Object result = queue.getFirst();
        queue.removeFirst();
        size--;
        return result;
    }


    @Override
    public String toString()
    {
        StringBuilder stringBuilder = new StringBuilder("[");
        Iterator iterator = queue.iterator();
        while (iterator.hasNext())
        {
            stringBuilder.append(iterator.next()).append(",");
        }
        stringBuilder.deleteCharAt(stringBuilder.lastIndexOf(","));
        stringBuilder.append("]");
        return stringBuilder.toString();
    }

    public void clear()
    {
        queue.clear();
    }

}
